package com.gzbsoft.sc;
import cn.hutool.core.util.ClassUtil;
import com.gzbsoft.sc.common.config.QiNiuConfig;
import io.ebean.DB;
import io.ebean.DocumentStore;
import io.ebean.annotation.DocStore;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.ebean.repository.config.EnableEbeanRepositories;

import java.util.Set;
@SpringBootApplication
@EnableEbeanRepositories
@EnableConfigurationProperties({QiNiuConfig.class})
public class ScApplication {
    public static void main(String[] args) {
        SpringApplication.run(ScApplication.class, args);
        indexAllEntity();
    }
    private static void indexAllEntity() {
        Set<Class<?>> entityClassSet = ClassUtil.scanPackageByAnnotation("com.gzbsoft.sc", DocStore.class);
        DocumentStore docStore = DB.getDefault().docStore();
        entityClassSet.forEach(clazz -> docStore.dropIndex(clazz.getSimpleName().toLowerCase()));
        entityClassSet.forEach(docStore::indexAll);
    }
}
